<template>
	<view class="container page">
		<welcome v-if="isShowPop" @hidePop="hidePop"></welcome>
		<template v-else>
			<top-search></top-search>
			<!-- 轮播图开始 -->
			<view class="banner-box mar-t-12 over-hide" style="height: 146px !important;">
				<swiper
					class="banner"
					style="height: 146px !important;"
					indicator-color="#d5d5d5"
					indicator-active-color="#ffffff"
					:indicator-dots="true"
					:autoplay="autoplay"
					:interval="interval"
					:duration="duration"
				>
					<swiper-item class="flex-column flex-1" v-for="(item,index) in banners" :key="index" @click="previewImage(banners,index)">
						<image  class="banner-item" :src="item.image" mode="widthFix" lazy-load='true'></image>
					</swiper-item>
				</swiper>
			</view>
			<!-- 轮播图结束 -->
			
			<!-- 金刚区 -->
			<view class="district flex mar-t-20 text-center">
				<navigator
					url="/pages/edu/list"
					open-type="navigate"
					hover-class="none"  
					class="flex-1">
					<image class="dis-icon" src="../../static/icons/index/zil.png"></image>
				<view class="mar-t-"><text class="font-color-666 font-500 font-size-15">家教资源</text></view>
				</navigator>
				<navigator
					url="/pages/activity/list"
					open-type="navigate"
					hover-class="none" 
					class="flex-1"
				>
					<image class="dis-icon" src="../../static/icons/index/baom.png"></image>
					<view class="mar-t-"><text class="font-color-666  font-500 font-size-15">活动报名</text></view>
				</navigator>
				<navigator
				url="/pages/yuyue/index"
				open-type="navigate"
				hover-class="none" 
				class="flex-1"
				>
					<image class="dis-icon" src="../../static/icons/index/yy.png"></image>
					<view class="mar-t-"><text class="font-color-666  font-500 font-size-15">咨询预约</text></view>
				</navigator>
				<navigator url="/pages/social/homePage" hover-class="none" open-type="navigate" class="flex-1">
					<image class="dis-icon" src="../../static/icons/index/ceshi.png"></image>
					<view class="mar-t-"><text class="font-color-666  font-500 font-size-15">关爱帮扶</text></view>
				</navigator>
			</view>
			<!-- 金刚区结束-->
			<!-- 广告位 -->
			<navigator url="/pages/test/test" 	hover-class="none" open-type="navigate" class="ad-content mar-t-20" v-if="store.state.app_config&&store.state.app_config.ad_img">
				<image class="ad-poster" :src="store.state.app_config.ad_img"></image>
			</navigator>
			<!-- 广告位结束 -->
			<!-- 推荐咨询师 -->
			<view class="mar-t-20 mar-b-20">
				<view class="flex align-center" style="padding-right: 14rpx;">
					<view class="font-color-333 font-bold font-size-18 font-fa-me flex-1" style="padding-left: 20rpx;">推荐文章</view>
					<navigator 
					 	url="/pages/edu/list"
						open-type="navigate"
						hover-class="none"  
						class="flex align-center justify-end">
						<text class="font-color-999 font-size-14">查看更多</text>
						<text class="iconfont icon-youjiantou font-color-999 font-size-12 mar-l-3"></text>
					</navigator>
				</view>
				<article-list :range="edu_list"></article-list>
			</view>
			<!-- 推荐咨询师结束 -->
			<no-more v-if="index_page >= total_page"></no-more>
			<tab-footer></tab-footer>
			<floatBtn @onFloatBtnClicked="onFloatBtnClicked"></floatBtn>
			<!-- https://vkceyugu.cdn.bspapp.com/VKCEYUGU-767674fd-0f0e-4801-90e6-bef27c2e36df/6bfb68af-5fe1-4cb8-880b-0a2f00a2c404.png -->
		</template>
	</view>
</template>

<script>
import topSearch from '@/components/top-search'
import articleList from '@/components/article-list'
import welcome from '@/components/welcome'
import floatBtn from '@/components/floatBtn.vue'
import {getBanners,getEduList,getUserInfo} from '@/utils/http'
export default {
	data() {
		return {
			autoplay: true,
			interval:6000,
			duration:500,
			banners:'',
			bannerImgs:[],
			index_page:0,
			total_page:1,
			edu_list:[],//咨询师列表
			isShowPop:true,
			ticket:'',
			sp:''
		}
	},
	components:{
		topSearch,articleList,welcome,floatBtn
	},
	onShow() {
		console.log('onShow')
		console.log('this.ticket',this.ticket)
		console.log('this.sp',this.sp)
		// if(!this.$store.state.user_info.nickname){
		// 	if(this.ticket){
		// 		this.login.zwlogin(this.ticket,decodeURIComponent(this.sp));
		// 	}
		// }
	},
	onLoad(options) {
		console.log('onLoad')
		if(this.isShowPop){
			uni.hideTabBar();
		}else{
			uni.showTabBar()
		}
		// if(options.ticket){
		// 	this.common.zwlogin(options.ticket)
		// }
		console.log('getPageUrl',this.getPageUrl())
		console.log('href',location.href)
		console.log('ticket:',options.ticket)
		console.log('this.$store.state.user_info',this.$store.state.user_info)
		// if(uni.getStorageSync('app_type')=='zwapp'){
		// 	if(!this.$store.state.user_info.nickname){
		// 		this.ticket = options.ticket || '';
		// 		this.sp = options.sp || '/';
		// 		if(this.ticket){
		// 			this.login.zwlogin(this.ticket,decodeURIComponent(this.sp));
		// 		}
		// 	}
		// }
		if(uni.getStorageSync('app_type')=='zwapp'){
			this.zwLogin()
		}
		
		this.getUserInfoEvent();
		this.getBanner();
		this.getEduList();
		
		// ZWJSBridge.monitorTrace({
		// 	monitorType: 'success',
		// 	module: 'Login',
		// 	modulePoint: 'password',
		// 	bizInfo: {
			
		// 	}
		// }).then((result) => {
		// 	console.log(result);
		// }).catch((error) => {
		// 	console.log(error);
		// });
	},
	methods: {
		onFloatBtnClicked(){
			uni.navigateTo({
				url:'/pages/kefu/kefu'
			})
		},
		hidePop(){
			console.log('hidePop')
			this.isShowPop=false
			uni.showTabBar()
		},
		previewImage(banners,index) {
			uni.previewImage({
				urls:this.bannerImgs,
				current:index,
				loop:true
			})
		},
		zwLogin(){
			let ticket = ''
			if(location.href.indexOf('ticket')>-1){
				ticket = this.getQueryVariable('ticket') || location.href.split('&ticket')[1].split('=')[1].split('&sp')[0];
			}else{
				ticket = this.getQueryVariable('ticket') || '';
			}
			const sp = this.getQueryVariable('sp') || '/pages/index/index';
			console.log('sp参数'+sp);
			if(ticket){
				this.login.zwlogin(ticket,decodeURIComponent(sp));
			}
		},
		getUserInfoEvent() {
			getUserInfo().then(res=>{
			    if(res){
					console.log('==============getUserInfo——res',res)
					if(res.code==401){
						this.zwLogin()
					}else{
						this.user_info = res
						uni.setStorageSync('user_info', res)
						this.store.commit('fn_set_user_info',res)
					}
			        
			    }
			})
		},
		zxOnline(){
			uni.showModal({
				title: '提示',
				content: '模块正在接入中,敬请期待...',
				success: function (res) {
					// if (res.confirm) {
					// 	console.log('用户点击确定');
					// } else if (res.cancel) {
					// 	console.log('用户点击取消');
					// }
				}
			});
		},
		getBanner(){
			getBanners({'num':8,'pos':'home'}).then(res=>{
				if(res){
					this.banners = res.data
					this.banners.forEach(item=>{
						this.bannerImgs.push(item.image)
					})
				}
				
			})
		},
		getEduList(){
			
			getEduList({page:this.index_page + 1}).then(res=>{
				if(res){
					this.edu_list = [...this.edu_list,...res.data]
					this.index_page = res.current_page;
					this.total_page = res.last_page;
				}
			})
		},
		
	},
	//下拉刷新
	onPullDownRefresh(){
		this.index_page = 0;
		this.total_page = 1;
		this.edu_list = []
		this.getEduList();
	},
	//上拉加载
	onReachBottom(){
		if(this.index_page < this.total_page){
			this.getEduList();
		}
	}
}
</script>

<style scoped>
	.banner-item{
		height: 146px !important;
	}


</style>
